import { createRouter, createWebHistory } from "vue-router";
import Login from "@/views/Login.vue";
import UserLayout from "@/views/user/UserLayout.vue";
import MerchantLayout from "@/views/merchant/MerchantLayout.vue";
import AdminLayout from "@/views/admin/AdminLayout.vue";

const routes = [

    { path: '/', redirect: '/login' },
    { path: '/login', component: Login }, // 登录页面

  // 用户的主页面和子路由
  {
    path: '/user',
    component: UserLayout,
    redirect: '/user/carBrowse', // 默认重定向到车辆浏览
    children: [
      { path: 'list', name: "userList", component: () => import("@/views/user/UserList.vue") },
      { path: 'info', name: "userInfo", component: () => import("@/views/user/UserInfo.vue") },
      { path: 'resetPassword', name: "resetPassword", component: () => import("@/views/user/RestPassword.vue") },
      { path: 'carBrowse', name: "carBrowse", component: () => import("@/views/user/CarBrowse.vue") },
      { path: 'carDetail/:id', name: "carDetail", component: () => import("@/views/user/CarDetail.vue") },
// 在第23行后添加以下路由：

// 租车服务模块路由
      { path: 'rental/process/:carId', name: "rentalProcess", component: () => import("@/views/user/rental/RentalProcess.vue") },
      { path: 'rental/orders', name: "myOrders", component: () => import("@/views/user/rental/MyOrders.vue") },
      { path: 'rental/payment/:orderId', name: "paymentPage", component: () => import("@/views/user/rental/PaymentPage.vue") },

// 个人信息维护模块路由
      { path: 'profile/management', name: "profileManagement", component: () => import("@/views/user/profile/ProfileManagement.vue") },
      { path: 'profile/changePassword', name: "passwordChange", component: () => import("@/views/user/profile/PasswordChange.vue") },
      { path: 'profile/favorites', name: "myFavorites", component: () => import("@/views/user/profile/MyFavorites.vue") },
    ]
  },

  // 商家的主页面和子路由
  {
    path: '/merchant',
    component: MerchantLayout,
    children: [
      { path: '/orderList', name: "orderList", component: () => import("@/views/merchant/OrderList.vue") },
      { path: '/carList', name: "carList", component: () => import("@/views/merchant/CatList.vue") },
      {
        path: 'merchantInfo/:id',
        name: 'merchantInfo',
        component: () => import('@/views/merchant/MerchantInfo.vue')
      },
      { path: '/resetPassword', name: "resetPassword", component: () => import("@/views/merchant/RestPassword.vue")},
      // 新增车辆查询和添加路由
      { path: '/vehicle-query', name: "vehicleQuery", component: () => import("@/views/merchant/VehicleQuery.vue") },
      { path: '/vehicle-add', name: "vehicleAdd", component: () => import("@/views/merchant/VehicleAdd.vue") },
      { path: '/vehicle-edit/:id?', name: "vehicleEdit", component: () => import("@/views/merchant/VehicleEdit.vue") },
      { path: '/merchant/vehicle-edit/:id',name: 'vehicleEdit', component: () => import('@/views/merchant/VehicleEdit.vue')},
      { path: '/paymentAmount',name: 'paymentAmount',component: () => import("@/views/merchant/payCharts/PaymentAmount.vue")},

    ]
  },

  // 管理员的主页面和子路由
  {
    path: '/admin',
    redirect: '/admin/user/list',
    component: AdminLayout,
    children: [
  // 用户管理
  {
    path: 'user/list', name: 'UserList', component: () => import('@/views/admin/UserList.vue')
  },
  // 商家管理
  {path: 'merchant/pending', name: 'PendingMerchants', component: () => import('@/views/admin/PendingMerchants.vue')
  },
  {path: 'merchant/approved', name: 'ApprovedMerchants', component: () => import('@/views/admin/ApprovedMerchants.vue')
  },
  // 订单管理
  {path: 'order/list', name: 'OrderList', component: () => import('@/views/admin/OrderList.vue')
  },
  // 信息统计
  {path: 'statistics', name: 'Statistics', component: () => import('@/views/admin/Statistics.vue')
  },
  {path: 'resetPassword', name: 'ResetPassword', component: () => import('@/views/admin/RestPassword.vue')
  }
    ]
  }
];

const router = createRouter({
  history: createWebHistory(),
  routes
});

export default router;
